package com.wms.auto;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

public class CreateDao {

	private static String PROP_FILE_PATH = "com.wms.data.dao";
	private static String PROP_DEMP_FILE_NAME = "DemoDao.jtxt";
	
	private static String PROP_FILE_EN = "UTF-8";
	
	public void create(String tableName) throws IOException {
		
		// 数据处理 
		String strName = CreateUtils.getNameToAaA(tableName);
		String inFilePath = CreateFile.class.getResource("").getPath() + PROP_DEMP_FILE_NAME;
//		String outFilePath = Role.class.getResource("").getPath() + strPojoName + ".java";
		String outFilePath = "E:/workspace/WMS/WMS/src/com/wms/data/dao/" + strName + "Dao" + ".java";
		
		File outF = new File(outFilePath);
		
		if (outF.exists()) {
			
			System.out.println("This is file existsed....table name: " + tableName + "");
			
			return;
		}
		
		// 以源文件编码格式读取源文件
		BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(inFilePath), PROP_FILE_EN));
		
		// 以目标文件编码格式输出目标文件
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFilePath), PROP_FILE_EN)));
		
		String reading;
		
		int lineIndex = 0;
		
		while ((reading = in.readLine()) != null) {
			
			lineIndex++;
			
			reading = StringUtils.replace(reading, "Demo", strName);
			
			out.println(reading);
		}
		
		out.close();
		in.close();
	}
}